<?php
namespace Home\Controller;

class ContactController extends BaseController {

    public function index(){
        $this->display();
    }

    public function submit(){
        $ex = D('Contact')->where(['ip'=>get_client_ip(), 'date'=>date('Y-m-d')])->find();
        if($ex){
            $this->ajaxReturn(['code'=>CODE_ERROR,'msg'=>'Already submit.']);
        }

        $ob = D('Contact');
        if(!$ob->create()){
            $this->ajaxReturn(['code'=>CODE_ERROR,'msg'=>$ob->getError()]);
        }

        $server = I('server');
        $cdn = I('cdn');

        $ob->date = date('Y-m-d');
        $ob->ip = get_client_ip();
        $ob->content = '公有云:'.implode(',', $server).'|cdn:'.implode(',', $cdn);
        $id = $ob->add();
        if(!$id){
            $this->ajaxReturn(['code'=>CODE_ERROR,'msg'=>'Failed.']);
        }

        $this->ajaxReturn(['code'=>CODE_SUCCESS,'msg'=>'Success.']);
    }
}